/*
 * Copyright (c) 2012,东方口岸科技有限公司
 * All rights reserved.
 * 文件名称：DtfRouterRepMessageReceiver.java
 * 摘    要：
 * 版本：1.0
 * 作    者：fengzhiyong
 */
package com.cneport.transfer.router.biz;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.cneport.transfer.constant.StatusConstants;
import com.cneport.transfer.message.dtf.DtfCtrlRep;
import com.cneport.transfer.router.model.RouterResponse;
import com.cneport.transfer.router.support.service.RouterResponseService;
import com.cneport.transfer.router.support.service.SequenceService;
import com.cneport.transfer.util.XmlSerializer;

public class DtfRouterRepMessageReceiver {
    private static Logger logger = Logger
            .getLogger(DtfRouterRepMessageReceiver.class);
    @Autowired
    private SequenceService sequenceService;
    @Autowired
    private RouterResponseService routerResponseService;
    public void dtfRouterRep2DB(String RouterRepMessage) {
        RouterResponse routerResponse = new RouterResponse();
        DtfCtrlRep dtfCtrlRep = new DtfCtrlRep();
        try {
            dtfCtrlRep = (DtfCtrlRep) XmlSerializer.deSerialize(
                    RouterRepMessage, DtfCtrlRep.class);
            routerResponse.setDealTime(new Date());
            if (dtfCtrlRep.getRepCode() > 0) {
                routerResponse.setFlag(StatusConstants.RETFLAG_T);
            } else if (dtfCtrlRep.getRepCode() <= 0) {
                routerResponse.setFlag(StatusConstants.RETFLAG_F);
            }
            routerResponse.setInfo(dtfCtrlRep.getRepInfo());
            routerResponse.setMessageId(dtfCtrlRep.getMsgId());
            routerResponse.setNote(dtfCtrlRep.getNote());
            routerResponse.setOriMessageId(dtfCtrlRep.getOriMsgId());
            routerResponse.setRouteResponseSeq(sequenceService.getSequence("routerRepSeq"));
            routerResponseService.insertRouterResponse(routerResponse);
        } catch (Exception e) {
            logger.error("路由回执报文解析错误！");
        }
    }
}
